# -*- coding: utf-8 -*-
import os
import sys
from optparse import make_option

from django.core.management.base import LabelCommand, CommandError
from docs.models import Project
from docs.repository_handlers import SubversionHandler

handlers_dict = {'svn':SubversionHandler,}

class Command(LabelCommand):
#    option_list = LabelCommand.option_list + (
#        make_option('-t', '--to', dest='to', default=None,
#                    help='The version you want to update to.'),
#
#    )
    help = "Sync project docs for the given label(s) in the current database."
    def handle_label(self, label, **options):
        try:
            project = Project.objects.get(slug = label)
            print "found project %s in database." % label
            if project.repository_type not in handlers_dict:
                print "no handlers for project '%s 'with type '%s'." % (label,project.repository_type)
                return
            handler = handlers_dict[project.repository_type](project)
            handler.handle()
        except Project.DoesNotExist:
            print "project %s didn't exist in database." % label
            return